package com.zhou.common.mybatis.template.shiro.zhou.controller;

import com.zhou.common.mybatis.template.shiro.zhou.entity.UserCenterAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/login/")
public class LoginController {


    //可以这样写，但会丢掉某些处理（并发会话控制，changeSessionId）
    @PostMapping("/pwd2")
    public UserCenterAuthenticationToken loginByPwd(HttpServletResponse response, HttpServletRequest request, @RequestBody LoginAo loginAO) {
        //处理用户密码登录
        UserCenterAuthenticationToken authenticationToken=new UserCenterAuthenticationToken(loginAO.getLoginName(),"TOKEN");
        SecurityContextHolder.getContext().setAuthentication(authenticationToken);
        //登录成功后的一些处理
//        sessionAuthenticationStrategy.onAuthentication(authenticationToken,request,response);
        return authenticationToken;
    }

    @PostMapping("/pwd1")
    public Authentication loginByPwd() {
        return SecurityContextHolder.getContext().getAuthentication();
    }


    @GetMapping("/pwd1")
    public Authentication loginByPwd1() {
        return SecurityContextHolder.getContext().getAuthentication();
    }
}
